package com.biqee.action.tuan;

import java.util.List;

import com.biqee.action.base.BaseAction;
import com.biqee.exception.BusinessUnCheckedException;
import com.biqee.exception.ErrorCode;
import com.biqee.model.common.PageInfoObject;
import com.biqee.model.db.BqTuan;
import com.biqee.model.page.ItemTuanVO;
import com.biqee.model.page.ItemVO;
import com.biqee.service.bq.BqQueryRelationService;
import com.biqee.service.bq.BqTuanService;
import com.biqee.util.StringUtil;

public class ListAction extends BaseAction{

	private static final long serialVersionUID = 1L;
	
	private PageInfoObject page = new PageInfoObject();
	
	private ItemTuanVO itemTuanVO ;
	
	private BqTuan bqTuan ;
	
	private List<ItemVO> itemsList ;
	
	private Integer tuanId ;
	
	private BqQueryRelationService bqQueryRelationService ;
	
	private BqTuanService bqTuanService;
	
	public String list(){
		bqTuan = bqTuanService.getById(tuanId);
		if (bqTuan != null) {
			itemTuanVO = new ItemTuanVO();
			itemTuanVO.setBqTuan(bqTuan);
		} else {
			throw new BusinessUnCheckedException(ErrorCode.BIZ_TUAN_001);
		}
		
		page.addParam("tuanId", tuanId);
		if(StringUtil.isBlank(page.getSort())){
			page.setSort("distancePrice");
		}
		
		itemsList = bqQueryRelationService.listRelationItemsByPage(page);
		return "list";
	}
	
	public String listAll(){
		return "list";
	}
	
	public Object getModel() {
		page.setLimit(40);
		return page;
	}

	public PageInfoObject getPage() {
		return page;
	}

	public void setPage(PageInfoObject page) {
		this.page = page;
	}

	public ItemTuanVO getItemTuanVO() {
		return itemTuanVO;
	}

	public void setItemTuanVO(ItemTuanVO itemTuanVO) {
		this.itemTuanVO = itemTuanVO;
	}

	public List<ItemVO> getItemsList() {
		return itemsList;
	}

	public void setItemsList(List<ItemVO> itemsList) {
		this.itemsList = itemsList;
	}

	public Integer getTuanId() {
		return tuanId;
	}

	public void setTuanId(Integer tuanId) {
		this.tuanId = tuanId;
	}

	public void setBqQueryRelationService(
			BqQueryRelationService bqQueryRelationService) {
		this.bqQueryRelationService = bqQueryRelationService;
	}

	public void setBqTuanService(BqTuanService bqTuanService) {
		this.bqTuanService = bqTuanService;
	}


}
